package com.raven.craft.code.generator.project.antijson.type;

import java.util.Set;

/**
 * @author raven
 * @date 2020/08/30
 **/
public interface Type {
    static Type reduce(Type accumulator, Type other) {
        if (accumulator instanceof NullType || accumulator instanceof EmptyElementType) return other;
        if (other instanceof NullType || other instanceof EmptyElementType) return accumulator;

        if (accumulator.getClass() != other.getClass()) {
            throw new IllegalStateException("Type mismatched");
        }

        if (accumulator instanceof Mergeable) {
            ((Mergeable) accumulator).merge(other);
            return accumulator;
        }
        // 普通基础类型
        return accumulator;
    }

    Set<String> getImports();

    String getName();

}

